package com.itheima.cases_demo.local_date_time;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

public class Test2 {
    public static void main(String[] args) {
        // LocalDateTime 本地日期时间类

        LocalDateTime now = LocalDateTime.now();
        System.out.println(now); // 2023-07-30T20:44:08.185339500

        // 获取日期信息
        int year = now.getYear(); // 获取年
        System.out.println(year); // 2023

        int monthValue = now.getMonthValue();// 获取月
        System.out.println(monthValue); // 7

        int dayOfMonth = now.getDayOfMonth(); // 获取月份的第几天
        System.out.println(dayOfMonth); // 30

        int dayOfYear = now.getDayOfYear(); // 一年的第几天
        System.out.println(dayOfYear); // 211

        int dayOfWeek = now.getDayOfWeek().getValue(); // 周几
        System.out.println(dayOfWeek); // 7

        int hour = now.getHour(); // 获取小时数
        System.out.println(hour); // 20

        int minute = now.getMinute(); // 获取分钟数
        System.out.println(minute); // 46

        int second = now.getSecond(); // 获取秒数
        System.out.println(second); // 4

        int nano = now.getNano(); // 获取纳秒
        System.out.println(nano); // 728242100

        System.out.println("---------------");


        // 反实例化
        LocalDateTime past = LocalDateTime.of(2011, 4, 12, 23, 45, 12);
        System.out.println(past); // 2011-04-12T23:45:12

        // LocalDate  LocalTime 合成 LocalDateTime
        LocalDate now1 = LocalDate.now();
        LocalTime now2 = LocalTime.now();
        LocalDateTime newNow = LocalDateTime.of(now1, now2);
        System.out.println(newNow); // 2023-07-30T20:51:23.689053100
    }
}
